package polymorphsm3;

public class Test1 {
    public static void main(String[] args) {
        //目标：认识多态代码
        //1，多态的好处：右边对象解耦合
        Animal a1 = new Tortoise();
        a1.run();
        //强制类型转换：
        Tortoise t1 =(Tortoise) a1;
        t1.shrinkHead();
        System.out.println("=======================");
//
        Wolf w = new Wolf();
        go(w);

//        Tortoise t = new Tortoise();
//        go(t);

    }


//多态的好处：父类类型的变量作为参数时，可以接收子类对象
    public static void go(Animal a)
    {
        System.out.println("开始。。。。。");
        a.run();

        if(a instanceof Tortoise)
        {
            Tortoise t = (Tortoise) a;
            t.shrinkHead();
        }
        else if(a instanceof Wolf)
        {
            Wolf w = (Wolf)a;
            w.eatsheep();
        }
    }
}